
<template>

  <div class="app-container">

    <div class="filter-container">
      <!-- 未遂事故题目：   <el-input v-model="listQuery.faultTitle" placeholder="题目" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
      未遂事故地点：     <el-input v-model="listQuery.faultLocation" placeholder="地点" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
      未遂事故发生开始时间： <el-input v-model="listQuery.startDate" placeholder="开始时间" type="date" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
      未遂事故发生结束时间： <el-input v-model="listQuery.endDate" placeholder="结束时间" type="date" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        查询
      </el-button>
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">
        新增
      </el-button>
      <el-button class="filter-item" type="primary" icon="el-icon-download">
        下载
      </el-button> -->
      <!--<el-checkbox v-model="showReviewer" class="filter-item" style="margin-left:15px;" @change="tableKey=tableKey+1">
        reviewer
      </el-checkbox> -->
    </div>
    <div>
      <!-- Note that row-key is necessary to get a correct row order. -->
      <el-table ref="dragTable" v-loading="listLoading" :data="list" row-key="id" border fit highlight-current-row style="width: 100%">

        <el-table-column class-name="status-col" label="部门" width="110">
          <template slot-scope="scope">
            <span @click="handleDetail(scope.row)">{{ scope.row.department.deptName }}</span></template>
        </el-table-column>
        <el-table-column align="center" label="职员" width="95">
          <template slot-scope="scope">
            <span @click="handleDetail(scope.row)">{{ scope.row.stuser.userName }}</span></template>
        </el-table-column>

        <el-table-column min-width="300px" label="stop卡累积分数">
          <template slot-scope="scope">
            <span @click="handleDetail(scope.row)">{{ scope.row.stopscore }}</span></template>
        </el-table-column>
        <el-table-column min-width="300px" label="未遂事故累积分数">
          <template slot-scope="scope">
            <span @click="handleDetail(scope.row)">{{ scope.row.faultscore }}</span></template>
        </el-table-column>
        <el-table-column min-width="300px" label="灾害预防累积分数">
          <template slot-scope="scope">
            <span @click="handleDetail(scope.row)">{{ scope.row.disasterscore }}</span></template>
        </el-table-column>
        <el-table-column min-width="300px" label="剩余分数">
          <template slot-scope="scope">
            <span @click="handleDetail(scope.row)">{{ scope.row.lastscore }}</span></template>
        </el-table-column>
      </el-table>
    </div>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="fechData" />

  </div>
</template>

<script>
// import MarkdownEditor from '@/components/MarkdownEditor'

import { personScoreList } from '@/api/reward'

import Sortable from 'sortablejs'
// import { parseTime } from '@/utils'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination

// arr to obj, such as { CN : "China", US : "USA" }

export default {
  name: 'Reward',
  components: { Pagination },
  directives: { waves },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }

  },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      faultTitle: null,
      editList: null,

      sortable: null,
      oldList: [],
      newList: [],
      // 参数条件
      listQuery: {
        page: 1,
        limit: 20,
        faultTitle: null,
        faultLocation: null,
        startDate: null,
        endDate: null
      },
      personlist: null,
      deptlist: null,
      faultNameList: null,
      temp: {
        id: '',
        stopscore: '',
        faultscore: '',
        disasterscore: '',
        createdate: '',
        stuser: '',
        department: ''
      },
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '修改',
        create: '新增',
        detail: '明细',
        detailreport: '未遂事故报告'
      },
      dialogPvVisible: false,
      pvData: [],
      rules: {
        type: [{ required: true, message: 'type is required', trigger: 'change' }],
        // timestamp: [{ type: 'faultTime', required: true, message: 'timestamp is required', trigger: 'change' }],
        title: [{ required: true, message: 'title is required', trigger: 'blur' }]
      },
      downloadLoading: false
    }
  },
  created() {
    this.fechData()
  },
  methods: {
    fechData() {
      personScoreList(this.listQuery).then(response => {
        this.listLoading = true
        this.list = response.personscore
        this.showList = response.personscore
        // console.log('888888888888888' + response.rewardList)
        this.listLoading = false
      })
    },
    handleCreate() {
      this.resetTemp()
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },

    handleDownload() {

    },
    showReviewer() {

    },
    handleFilter() {
      this.listQuery.page = 1
      this.fechData()
    },

    getHtml() {

    },

    setSort() {
      const el = this.list[0]

      this.sortable = Sortable.create(el, {
        ghostClass: 'sortable-ghost', // Class name for the drop placeholder,
        setData: function(dataTransfer) {
          // to avoid Firefox bug
          // Detail see : https://github.com/RubaXa/Sortable/issues/1012
          dataTransfer.setData('Text', '')
        },
        onEnd: evt => {
          const targetRow = this.list.splice(evt.oldIndex, 1)[0]
          this.list.splice(evt.newIndex, 0, targetRow)

          // for show the changes, you can delete in you code
          const tempIndex = this.newList.splice(evt.oldIndex, 1)[0]
          this.newList.splice(evt.newIndex, 0, tempIndex)
        }
      })
    }
  }
}
</script>

<style>
.sortable-ghost{
  opacity: .8;
  color: #fff!important;
  background: #42b983!important;
}
</style>

<style scoped>
.icon-star{
  margin-right:2px;
}
.drag-handler{
  width: 20px;
  height: 20px;
  cursor: pointer;
}
.show-d{
  margin-top: 15px;
}
</style>
